﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _004
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Program names = new Program();
            names[0] = "C#中文网";
            names[1] = "http://c.biancheng.net/";
            names[2] = "C#教程";
            names[3] = "索引器";
            //使用带有int参数的第一个索引器
            for(int i=0;i<Program.size;i++)
            {
                Console.WriteLine(names[i]);
            }
            //使用带有string参数的第二个索引器
            Console.WriteLine(@"C#教程的索引为：{0}", names["C#教程"]); 
            Console.ReadKey();
        }
        public static int size = 10;
        private string[] namelist = new string[size];
        public Program()
        {
            for(int i=0;i<size;i++)
            {
                namelist[i] = "NULL";
            }
        }
        public string this[int index]
        {
            get
            {
                string tmp;
                if(index>=0 && index<=size-1)
                {
                    tmp = namelist[index];
                }
                else
                {
                    tmp = "";
                }
                return (tmp);
            }
            set
            {
                if(index>=0 && index<=size-1)
                {
                    namelist[index] = value;
                }
            }
        }
        public int this[string name]
        {
            get
            {
                int index = 0;
                while(index<size)
                {
                    if (namelist[index]==name)
                    {
                        return index;
                    }
                    index++;
                }
                return index;
            }
        }
    }
}
